/*
 * @(#) BaseUtil
 *
 * <br> Copyright:  Copyright (c) 2017
 * <br> @author caijinhuang
 * <br> 2017-12-18 16:19:34
 */

package com.sunsharing.sharemeeting.util;

import com.sunsharing.share.common.base.IdGenerator;
import com.sunsharing.share.common.text.EncodeUtil;
import com.sunsharing.sharemeeting.entity.ExcelObject;

import java.io.UnsupportedEncodingException;
import java.security.NoSuchAlgorithmException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;


import com.sunsharing.sharemeeting.entity.User;

public class BaseUtil {
    /**
     * excel导入对象转换
     */
    public static List<User> getUserList(List<Object> excelObjectList) throws UnsupportedEncodingException, NoSuchAlgorithmException {
        List<User> ulist = new ArrayList<User>();
        for (int i = 0; i < excelObjectList.size(); i++) {
            ExcelObject obj = (ExcelObject) excelObjectList.get(i);
            User user = new User();
            user.setUserId(IdGenerator.uuid2());
            user.setUsername(obj.getUsername());
            String md5String = EncodeUtil.md5(obj.getPasswd());
            user.setPassword(EncodeUtil.encodeBase64(md5String.getBytes()));
            user.setNickname(obj.getNickname());
            user.setDepartment(obj.getDepartmentInfoId());
            user.setSex(obj.getSex());
            user.setEmail(obj.getEmail());
            // user.setPhone(obj.getPhone());
            user.setRoleId(obj.getRoleId());
            Timestamp time = new Timestamp(new Date().getTime());
            user.setLoginTime(time);
            user.setAlterTime(time);
            user.setCreateTime(time);
            ulist.add(user);
        }
        return ulist;
    }
}
